home *** CD-ROM | disk | FTP | other *** search
- (* Code from Pascal column in Micro Cornucopia Issue #40 *)
-
- MODULE Pic2File;
- (* Capture an image to a file as well as displaying it *)
-
- FROM ScrnStuff IMPORT Screen, ClrScr, GraphMode, TextMode, Scan,
- PixAddress, Buffer, SetBit, SetClock, ClrBit;
- FROM Terminal IMPORT KeyPressed, ReadString, WriteString;
- FROM Config IMPORT Xsize, Ysize;
- FROM FileSystem IMPORT File, Lookup, WriteNBytes, Close;
- FROM SYSTEM IMPORT SIZE, ADR;
-
- CONST
- TickSize = 1536; (* real time clock chip divisor, this value gave
- reasonable results. Subject to change. *)
- packsize = Xsize DIV 2 -1;
- VAR
- S [0b000h:0] : Screen; (* use appropriate constants for your adapter *)
- I, J, K, L : CARDINAL;
- B : Buffer;
- A : POINTER TO CHAR;
- BP : CARDINAL; (* not used except as throwaway parameter *)
- ch : CHAR;
- byteArray : ARRAY [0..packsize] OF CHAR;
- byteidx, w : CARDINAL;
- f : File;
- fname : ARRAY [0..40] OF CHAR;
-
- BEGIN
- ClrScr(S); (* clear the screen *)
- WriteString('Name of picture data file: ');
- ReadString(fname);
- GraphMode; (* put it in graphics mode *)
- Lookup(f,fname,TRUE); (* open/create file function *)
- SetClock(TickSize);
- FOR J := 0 TO Ysize-1 DO (* for now, just try for same resolution as screen *)
- byteidx := 0;
- Scan(B); (* capture a line od data *)
- FOR K := 0 TO Xsize-1 BY 8 DO (* Xsize is bits, do a byte at a time *)
- A := PixAddress(K,J,BP); (* calculate byte address *)
- (*==>*) ch := CHR(255); (* clear assembly variable *)
- (*ch := CHR(0); (* to get white on black *)*)
- FOR L := 0 TO 7 DO (* then do each bit in the byte *)
- IF ODD(K+L) THEN
- byteArray[byteidx] := CHR(ORD(byteArray[byteidx]) +
- ORD(B[K+L]));
- INC(byteidx);
- ELSE
- byteArray[byteidx] := CHR(ORD(B[K+L]) * 16);
- END;
- (*==>*) IF B[K+L] < 17C THEN
- ch := ClrBit(ch,7-L);
- (*ch := SetBit(ch,7-L); (* to get white on black *)*)
- END;
- END;
- A^ := ch; (* actual screen byte update here *)
- END;
- WriteNBytes(f,ADR(byteArray),SIZE(byteArray),w);
- END;
- Close(f);
- WHILE NOT(KeyPressed()) DO END; (* admire the picture for a bit *)
- ClrScr(S); (* then do orderly exit *)
- TextMode; (* should also SlowClock *)
- END Pic2File.